<?php
// 8/29/2009: Immanuel192 rewrite this code

class documentsmodule {
	function name() { return "Documents Module"; }
	function description() { return "Manage all documents of Kurtulus Credit, Law and Marka"; }
	function author() { return "ABSoft Viet Nam"; }

	function hasSources() { return true; }
	function hasContent() { return true; }
	function hasViews() { return true; }

	function supportsWorkflow() { return false; }

	function permissions($internal = "", $type=0) {
		if ($type == 0) {
			return array(
				'administrate'=>'Administrate',
				'configure'=>'Configure',
				'create'=>'Add sermons',
				'edit'=>'Edit sermons',
				'delete'=>'Delete sermons'
			);
		}
		else
		{
			return array('administrate','configure','create','edit','delete');
		}
	}

	function show($view,$loc = null, $title = "") {
		$_REQUEST['page']=1;
		$_REQUEST['flow_has_set']=1; // to compatipility with view_page
		exponent_flow_set(SYS_FLOW_PUBLIC,SYS_FLOW_SECTIONAL);
		include("actions/view_page.php");
	}

	function deleteIn($loc) {
		global $db;
		$db->delete('sermonmodule_link',"location_data='".serialize($loc)."'");
	}

	function copyContent($oloc,$nloc) {
		foreach ($db->selectObjects('sermonmodule_sermon',"location_data='".serialize($oloc)."'") as $l) {
			$l->location_data = serialize($nloc);
			$db->insertObject($l,'documentmodule_document');
		}
	}

	function searchName() {
		return exponent_lang_loadKey('modules/documentmodule/class.php','search_name');
	}
	
	/*
	   8/29/2009 immanuel192
	   This function create HTML content of spider item
	*/
	function spiderTemplate($album)
	{
	   global $db;
	   
			
			// create template content
			$template=new template("sermonmodule","_search");
			$template->assign("album",$album);
			ob_start();
			$template->output();
			$get_value=ob_get_contents();
			ob_end_clean(); 
			return $get_value;
  }
	

	function spiderContent($item = null) {
        return false;
		global $db;

		if (!defined('SYS_SEARCH')) require_once(BASE.'subsystems/search.php');

		$search = null;
		$search->category = 'Links';
		$search->ref_module = 'documentmodule';
		$search->ref_type = 'sermon_link';
		$search->view_link = '';

		if ($item) {
			$db->delete('search',"ref_module='documentmodule' AND ref_type='sermon_link' AND original_id=" . $item->id);
			$search->original_id = $item->id;
			$search->title = ' ' . $item->name . ' ';
			$search->body = ' ' . exponent_search_removeHTML($item->description) . ' ';
			$search->location_data = $item->location_data;
			$db->insertObject($search,'search');
		} else {
			$db->delete('search',"ref_module='documentmodule' AND ref_type='sermon_link'");
			foreach ($db->selectObjects('sermon_link') as $item) {
				$search->original_id = $item->id;
				$search->title = ' ' . $item->name . ' ';
				$search->body = ' ' . exponent_search_removeHTML($item->description) . ' ';
				$search->location_data = $item->location_data;
				$db->insertObject($search,'search');
			}
		}

		return true;
	}
}

?>
